﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using myschoolDal;
namespace school
{
    public partial class opensource : Form
    {
        private static string term;
        private static string source;
        private static string teacher;
        private static string _time;
        private static string location;
        private static int credit;

        public opensource()
        {
            InitializeComponent();
        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem == null || textBox3.Text.Trim() == "" || textBox7.Text.Trim() == "" || textBox4.Text.Trim() == "" || textBox9.Text.Trim() == "")
            {
                MessageBox.Show("错误：" + bug.Class1.worng4001);
            }
            else
            {
                term = comboBox1.SelectedItem.ToString();
                source = textBox3.Text.ToString();
                teacher = textBox7.Text.ToString();
                location = textBox4.Text.ToString();
                credit = Convert.ToInt32(textBox9.Text);
                for (int i = 0; i < checkedListBox1.Items.Count; i++)
                {
                    if (checkedListBox1.GetItemChecked(i))
                    {
                        string time = checkedListBox1.GetItemText(checkedListBox1.Items[i]);

                        if (manserver.GetStuSourceLocation(time, location).Tables[0].Rows.Count > 0)
                        {
                            MessageBox.Show("该时间该教室已经有课！", "提示");
                            break;
                        }
                    }
                }
                for (int i = 0; i < checkedListBox1.Items.Count; i++)
                {
                    if (checkedListBox1.GetItemChecked(i))
                    {
                        string time = checkedListBox1.GetItemText(checkedListBox1.Items[i]);
                        //将开课表的id得到
                        manserver.AddClassDetailInformation(source, term, teacher, location, _time, credit);
                        MessageBox.Show("添加成功", "提示");
                    }
                }
            }

        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
